package com.example.uitest;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

public class ListViewAdapter extends BaseAdapter implements OnClickListener{

	private LayoutInflater inflater = null;
	private ViewHolder holder = null;
	private Context mContext = null;
	private ArrayList<ListData> mListData = null;

	public ListViewAdapter(Context c , ArrayList<ListData> arrays){
		this.mContext = c;
		this.inflater = LayoutInflater.from(c);
		this.mListData = arrays;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mListData.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mListData.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		View v = convertView;
		
	    if (convertView == null) {
	        holder = new ViewHolder();
	 
	        inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	        v = inflater.inflate(R.layout.sns_moreview, null);
	 
	       
	        holder.tv_sns = (TextView) v.findViewById(R.id.moreview_tv_sns);
	        holder.btn_like = (Button) v.findViewById(R.id.moreview_btn_like);
	        holder.btn_dislike = (Button) v.findViewById(R.id.moreview_btn_dislike);
	        
	        v.setTag(holder);
	    }else{
	        holder = (ViewHolder) v.getTag();
	    }
	 
	    ListData mData = mListData.get(position);
	 
	    //holder.sns.setText(getItem(position).);
	    
	    holder.btn_like.setTag(position);
	    holder.btn_like.setOnClickListener(this);
	    
	    holder.btn_dislike.setTag(position);
	    holder.btn_dislike.setOnClickListener(this);
	    
	    return v;
	}	
	
	class ViewHolder{
		public TextView tv_sns = null;
		public Button btn_like = null;
		public Button btn_dislike = null;
		
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId()){
		
		case R.id.moreview_btn_like:
			break;
			
		case R.id.moreview_btn_dislike:
			break;
		}
	}
}
